package dl.bukkit.myststus.task;

import dl.bukkit.myststus.MyStatus;
import dl.bukkit.myststus.api.event.TaskEvent;
import dl.bukkit.myststus.configuration.imp.Config;
import org.bukkit.Bukkit;

import java.util.ArrayList;

public class Task extends TaskManager.MainTask {

    private final MyStatus plugin;

    public Task(MyStatus plugin) {
        this.plugin = plugin;
    }

    @Override
    public void run() {
        new ArrayList<>(Bukkit.getOnlinePlayers()).forEach(player -> Bukkit.getPluginManager().callEvent(new TaskEvent(player)));
    }

    @Override
    public void runTaskAsynchronously() {
        runTaskTimerAsynchronously(plugin, 0, Config.getInst().getInt("Trigger.Task.Tick"));
    }

    @Override
    public boolean isRegister() {
        return Config.getInst().getBoolean("Trigger.Task.Enable");
    }
}
